//
//  HZJRecommendCVCell.m
//  HZ_Beautiful_Music
//
//  Created by dllo on 16/4/1.
//  Copyright © 2016年 ui. All rights reserved.
//

#import "HZJRecommendCVCell.h"
#import "HJCarouselViewLayout.h"
#import "HZJTuiShowCVCell.h"
@interface HZJRecommendCVCell ()<UICollectionViewDataSource, UICollectionViewDelegate>

@property (nonatomic, strong) UICollectionView *collectionView;

@end

#define wide self.bounds.size.width


@implementation HZJRecommendCVCell

- (instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self creatCollection];
    }
    return self;
}

#pragma mark - 创建collectionview
- (void)creatCollection {
//    推荐界面三方。。
    HJCarouselViewLayout *layout = [[HJCarouselViewLayout alloc] initWithAnim:HJCarouselAnimCarousel];
    
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    layout.itemSize = CGSizeMake(self.bounds.size.width - 50, self.bounds.size.width - 50);
    
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, wide, self.bounds.size.height - 44) collectionViewLayout:layout];
    self.collectionView.backgroundColor = [UIColor clearColor];
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;

    [_collectionView registerClass:[HZJTuiShowCVCell class] forCellWithReuseIdentifier:@"HZJTuiShowCVCell"];
    
    [self.contentView addSubview:_collectionView];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.dataSource.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    /**
     *  这是推荐的cell
     */
    HZJTuiShowCVCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HZJTuiShowCVCell" forIndexPath:indexPath];
    cell.tuiJianModel = self.dataSource[indexPath.row];
    cell.backgroundColor = [UIColor clearColor];
    return cell;
    
}

#pragma mark - 点击推荐cell进入播放界面
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    [self.delegate JRecommendSendIndex:indexPath];
    
    [_collectionView deselectItemAtIndexPath:indexPath animated:YES];
}

#pragma mark - 从VC传递来的推荐界面数组
- (void)setDataSource:(NSMutableArray *)dataSource {
    
    _dataSource = dataSource;
    [_collectionView reloadData];
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
